package com.suao.web.controller.fruits;

import com.suao.common.annotation.Log;
import com.suao.common.core.controller.BaseController;
import com.suao.common.core.domain.AjaxResult;
import com.suao.common.core.page.TableDataInfo;
import com.suao.common.enums.BusinessType;
import com.suao.common.utils.poi.ExcelUtil;
import com.suao.fruits.domain.FruitsSpoilageInfo;
import com.suao.fruits.service.IFruitsSpoilageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 果店损耗管理Controller
 *
 * @author tyz
 * @date 2023-03-08
 */
@RestController
@RequestMapping("/fruits/FruitsSpoilageInfo")
public class FruitsSpoilageInfoController extends BaseController
{
    @Autowired
    private IFruitsSpoilageInfoService fruitsSpoilageInfoService;

    /**
     * 查询果店损耗管理列表
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(FruitsSpoilageInfo fruitsSpoilageInfo)
    {
        startPage();
        List<FruitsSpoilageInfo> list = fruitsSpoilageInfoService.selectFruitsSpoilageInfoList(fruitsSpoilageInfo);
        return getDataTable(list);
    }

    /**
     * 导出果店损耗管理列表
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:export')")
    @Log(title = "果店损耗管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FruitsSpoilageInfo fruitsSpoilageInfo)
    {
        List<FruitsSpoilageInfo> list = fruitsSpoilageInfoService.selectFruitsSpoilageInfoList(fruitsSpoilageInfo);
        ExcelUtil<FruitsSpoilageInfo> util = new ExcelUtil<FruitsSpoilageInfo>(FruitsSpoilageInfo.class);
        util.exportExcel(response, list, "果店损耗管理数据");
    }

    /**
     * 获取果店损耗管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(fruitsSpoilageInfoService.selectFruitsSpoilageInfoById(id));
    }

    /**
     * 新增果店损耗管理
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:add')")
    @Log(title = "果店损耗管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FruitsSpoilageInfo fruitsSpoilageInfo)
    {
        return toAjax(fruitsSpoilageInfoService.insertFruitsSpoilageInfo(fruitsSpoilageInfo));
    }

    /**
     * 修改果店损耗管理
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:edit')")
    @Log(title = "果店损耗管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FruitsSpoilageInfo fruitsSpoilageInfo)
    {
        return toAjax(fruitsSpoilageInfoService.updateFruitsSpoilageInfo(fruitsSpoilageInfo));
    }

    /**
     * 删除果店损耗管理
     */
    @PreAuthorize("@ss.hasPermi('fruits:FruitsSpoilageInfo:remove')")
    @Log(title = "果店损耗管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fruitsSpoilageInfoService.deleteFruitsSpoilageInfoByIds(ids));
    }
}
